package com.turnengine.client.local.action.command.gwt;

import static com.javabi.common.dependency.DependencyFactory.getDependency;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.javabi.codebuilder.generated.gwt.IGeneratedRemoteServiceServlet;
import com.javabi.command.IExecutableCommandResponse;
import com.javabi.command.errorcode.gwt.GwtErrorCodeException;
import com.javabi.command.executor.ICommandExecutorService;
import com.turnengine.client.local.action.bean.IActionTarget;
import com.turnengine.client.local.action.command.AddActionTarget;
import com.turnengine.client.local.action.enums.ActionTargetType;
import com.turnengine.client.local.unit.enums.UnitRelation;
import com.turnengine.client.local.unit.enums.UnitType;

/**
 * The Add Action Target Servlet.
 */
public class AddActionTargetServlet extends RemoteServiceServlet implements IGeneratedRemoteServiceServlet, AddActionTargetService {

	public IActionTarget addActionTarget(long loginId, int instanceId, int actionId, ActionTargetType target, UnitType type, UnitRelation relation) throws GwtErrorCodeException {
		AddActionTarget command = new AddActionTarget(loginId, instanceId, actionId, target, type, relation);
		ICommandExecutorService service = getDependency(ICommandExecutorService.class);
		IExecutableCommandResponse<IActionTarget> response = service.execute(command);
		if (response.hasErrors()) {
			throw new GwtErrorCodeException(response);
		}
		return response.getReturnValue();
	}
}
